<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%@include file="/common/common.jsp"%>
<%@include file="/common/skins/skin0/component.jsp" %>
<h:css href="/css/style1/style-custom.css"/>
<%--
- Author(s): pengweiling
- Date: 2012-07-06 08:57:21
- Description:
--%>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>
      订单修改申请
    </title>
    <script>
      //配置参数
      <% int ic = 0; %>
      gCfg = {
      <l:iterate property="cfg" id="id1">
         <% if (ic > 0){%>
         ,
         <%} %>
         '<b:write property="parameterCode" iterateId="id1"/>':'<b:write property="parameterValue" iterateId="id1"/>'
         <%ic++; %>
      </l:iterate>
      };
      
      //折扣规则
      <%ic=0; %>
      gRules = [
         <l:iterate property="rules" id ="id2">
         <% if (ic > 0){%>
         ,
         <%} %>
         {
           cCategory:'<b:write property="ccategory" iterateId="id2"/>',
           ndaysfrom:<b:write property="ndaysfrom" iterateId="id2"/>,
           ndaysto:<b:write property="ndaysto" iterateId="id2"/>,
           nratediscount:<b:write property="nratediscount" iterateId="id2"/>
         }
         <%ic++; %>
         </l:iterate>
      ];
      
    </script>    
    
<%
  String ua = request.getHeader( "User-Agent" );
  boolean isMSIE = ( ua != null && ua.indexOf( "MSIE" ) != -1 );
  if (isMSIE==true){

%>
<script type="text/javascript" src="OrderMgr/script/json2.js"></script>  
  
<%} %>  
    <script type="text/javascript" src="commonPick/script/utils.js"></script>    
    <script type="text/javascript" src="OrderMgr/script/order.js"></script>

  </head>
  <body>
    <%
       boolean showAudit = false;
       String isReadonly = "true";
       String orderStatus = "NONE";
       if (request.getAttribute("task") != null){
         isReadonly = "true";
         if (request.getAttribute("weordertasks") != null){
            commonj.sdo.DataObject sdo = (commonj.sdo.DataObject)request.getAttribute("weordertasks");
            orderStatus  = sdo.getString("cstatus");
            if (orderStatus.equalsIgnoreCase("S")){
               isReadonly = "false";
            }
            
            if (orderStatus.equalsIgnoreCase("B") || orderStatus.equalsIgnoreCase("P")){
               showAudit = true;
            }
         }
       }
       
       boolean isTodo = true;
       if (request.getAttribute("task") != null){
          commonj.sdo.DataObject sdo = (commonj.sdo.DataObject)request.getAttribute("task");
          if (sdo.get("cstatus") == null){
            isTodo = false;
            isReadonly = "true";
          }else if (sdo.getString("cstatus").equalsIgnoreCase("COMPLETE")){
            isTodo = false;
            isReadonly = "true";
          }
       }
    %>
    
            

             
    <e:datasource name="weordertasks" type="entity" path="com.hms.OrderMgr.order.WeOrdertasks" />
    <h:form name="data_form" action="com.hms.OrderMgr.OrderModify.flow" method="post" onsubmit="return submitDatacell(this);">
      <h:hidden property="weordertasks/iorderid" />
      <h:hidden property="task/itaskid" />      
      <h:hidden property="task/istepid" />  
      <h:hidden property="task/ctasktype" /> 
      <h:hidden property="task/nstepno" />     
      <h:hidden property="task/cstepname" />    
      <h:hidden property="task/iorderid" />    
      <h:hidden property="task/cstatus" />          
      <h:hidden property="task/cauditby" />   
      <l:notEmpty>
         <h:hidden property="task/aciton" />   
      </l:notEmpty>
      <l:empty>
         <input type="hidden" name="task/aciton" value="STARTUP"/>   
      </l:empty>
      
      <input type="hidden" name="_eosFlowAction" value="save" >
      
      <h:hiddendata property="criteria" />
      <h:hidden property="page/begin"/>
      <h:hidden property="page/length"/>
      <h:hidden property="page/isCount"/>
      <dataform id= "efa30c85-dbed-4340-a754-267fa9a49981">
          <table align="center" border="0" width="100%" class="form_table">
            <tr>
               <td class="form_label">
                  订单编号
               </td>
              <td colspan="5" style="color:blue">
                <b:write property="weordertasks/corderno"/>(
                <l:equal property="weordertasks/cstatus" targetValue="C">
                   取消
                </l:equal>
                <l:equal property="weordertasks/cstatus" targetValue="B">
                   待审核
                </l:equal>
                <l:equal property="weordertasks/cstatus" targetValue="P">
                   待支付确认
                </l:equal>    
                <l:equal property="weordertasks/cstatus" targetValue="Y">
                   审核确认
                </l:equal> 
                <l:equal property="weordertasks/cstatus" targetValue="I">
                   入住
                </l:equal>                                               
                <l:equal property="weordertasks/cstatus" targetValue="O">
                   已结
                </l:equal>        
                <l:equal property="weordertasks/cstatus" targetValue="X">
                   已退未结算
                </l:equal>      
                <l:equal property="weordertasks/cstatus" targetValue="D">
                   已结未退
                </l:equal>    
                <l:equal property="weordertasks/cstatus" targetValue="S">
                   未提交
                </l:equal>                                                                                
                )
              </td>               
            </tr>
            <tr>
              <td class="form_label">
                预订人
              </td>
              <td colspan="1">
                <h:text property="weordertasks/cbookname" style="width:200px;" readonly="<%=isReadonly %>" validateAttr="allowNull=false"/><font style="color:red">*</font>
              </td>
              <td class="form_label">
                预订人手机
              </td>
              <td colspan="1">
                <h:text property="weordertasks/cbooktel"  style="width:200px;" readonly="<%=isReadonly %>"/>
              </td>
              <td class="form_label">
                预定会员
              </td>
              <td colspan="1">
                <w:lookup property="weordertasks/cbookmemberid"  
                          displayProperty="weordertasks/memberName"
                          style="width:200px;" 
                          dialogTitle="选择会员"
                          allowInput="false"
                          readOnly="<%=isReadonly %>"
                          validateAttr="allowNull=false"
                          lookupUrl="com.hms.commonPick.WeMemberSelect.flow"/><font style="color:red">*</font>  

              </td>
            </tr>
            <tr>
              <td class="form_label">
                是否接机
              </td>
              <td colspan="1">
                <h:switchCheckbox checkedValue="Y" property="weordertasks/bispickup" uncheckedValue="N" disabled="<%=isReadonly %>"/>
              </td>
              <td class="form_label">
                接机时间
              </td>
              <td colspan="1">
                <w:date property="weordertasks/dpickupdate" style="width:200px;" readOnly="<%=isReadonly %>"  format="yyyy-MM-dd HH:mm:ss" />
              </td>
              <td class="form_label">
                销售员
              </td>
              <td colspan="1">
                <w:lookup property="weordertasks/csaler" 
                          style="width:200px;"
                          lookupUrl="com.hms.commonPick.OmEmployeeSelect.flow"
                          displayProperty="weordertasks/salesName"      
                          dialogTitle="选择销售员"  
                          readOnly="<%=isReadonly %>"  
                          validateAttr="allowNull=false"
                          allowInput="false"/><font style="color:red">*</font>
              </td>
            </tr>
            <tr>
              <td class="form_label">
                接机地点
              </td>
              <td colspan="1">
                <h:text property="weordertasks/cpickupaddress" style="width:200px;" readonly="<%=isReadonly %>"/>
              </td>
              <td class="form_label">
                接机人数
              </td>
              <td colspan="1">
                <h:text property="weordertasks/seeoffcounter" style="width:200px;" readonly="<%=isReadonly %>"/>
              </td>
              <td class="form_label">
                航班/车次
              </td>
              <td colspan="1">
                <h:text property="weordertasks/clineno" style="width:200px;" readonly="<%=isReadonly %>"/>
              </td>
            </tr>
            <tr>
              <td class="form_label">
                是否送机
              </td>
              <td colspan="1">
                <h:switchCheckbox checkedValue="Y" property="weordertasks/bisseeoff" uncheckedValue="N" disabled="<%=isReadonly %>"/>
              </td>
              <td class="form_label">
                送机时间
              </td>
              <td colspan="1">
                <w:date property="weordertasks/dseeoffdate" style="width:200px;" readOnly="<%=isReadonly %>"  format="yyyy-MM-dd HH:mm:ss" />
              </td>
              <td class="form_label">
                送机目的地
              </td>
              <td colspan="1">
                <h:text property="weordertasks/cseeoffaddress" style="width:200px;" readonly="<%=isReadonly %>"/>
              </td>
            </tr>
            <tr>
              <td class="form_label">
                客人来源
              </td>
              <td colspan="1">
                <d:select property="weordertasks/csourcename" nullLabel="请选择" dictTypeId="HMS_CUSTOMER_SRC" disabled="<%=isReadonly %>"/>
              </td>
              <td class="form_label">
                来源说明
              </td>
              <td colspan="3">
                <h:text property="weordertasks/csoucedescription" style="width:100%;" readonly="<%=isReadonly %>"/>
              </td>
            </tr>
            <tr>
              <td class="form_label">
                备注
              </td>
              <td colspan="5">
                <h:textarea property="weordertasks/cdescription" style="width:100%;" readonly="<%=isReadonly %>"/>
              </td>
            </tr>
            <tr class="form_bottom">
              <td colspan="6">
              <l:empty property="task/itaskid">
                <input type="submit" value="保存" class="button">
                <input type="button" value="提交" class="button" onclick="commitOrder()">       
              </l:empty>
                           
             
                <input type="button" value="返回" onclick="javascript:history.go(-1);" class="button">
              </td>
            </tr>
          </table>
      </dataform>
      
      
<w:layout height="40%" type="horizontal" width="100%">
  <w:layoutPanel width="100%">
    <w:tabPanel bodyStyle="" defaultTab="pgGress" height="" id="tabGress" titleStyle="" width="100%;height:100%;">
    
       <w:tabPage cache="true" id="pgGress" tabType="div" title="租房信息">
         <r:datacell height="320" pageSize="1000" entityType="com.hms.OrderMgr.order.WeOrdermodified" id="gress" isCount="false" readonly="false" submitXpath="weordertasks/modifies" width="100%" xpath="weordertasks/modifiesV">
           <l:empty property="task/itaskid">
             <r:toolbar location="top" tools="edit:add del"/>
           </l:empty>
           <l:notEmpty property="task/itaskid">
              <r:toolbar location="top" tools="edit:refresh"/>
           </l:notEmpty>
           
           <r:field fieldName="cgresno" label="客单号">
           </r:field>
                
           <r:field fieldName="cstatus" label="客单当前状态" onRefreshFunc="getGresStatus">
           </r:field>
                                 
           <r:field fieldName="csourceroomno" label="原房号">
           </r:field>
           
           <r:field fieldName="cnewroomno" label="新房号">
           <l:empty property="task/itaskid">
             <w:lookup lookupUrl="com.hms.commonPick.WeRoomSelect.flow"
                       dialogTitle="选择房间"
                       allowInput="false"
                       onReturnFunc="setRoomId"
             />
           </l:empty>           
           </r:field>
                      
           <r:field fieldName="dsourcearrdate" label="原抵店日期" width="126" onRefreshFunc="skipDate"></r:field>
                      
           <r:field fieldName="dnewarrdate" label="新抵店日期" nullText="必须输入" width="126" onRefreshFunc="skipDate">
           <l:empty property="task/itaskid">
             <w:date format="yyyy-MM-dd HH:mm:ss" />
           </l:empty>                         
           </r:field>
                                 
           <r:field fieldName="dsourcedepdate" label="原离店日期"  width="126" onRefreshFunc="skipDate"></r:field>
            
           <r:field fieldName="dnewdepdate" label="新离店日期"  width="126" onRefreshFunc="skipDate">
           <l:empty property="task/itaskid">
             <w:date format="yyyy-MM-dd HH:mm:ss" /> 
           </l:empty>           
                       
           </r:field>
  
           <r:field fieldName="biscancelgres" label="取消订房" width="60">
           <l:empty property="task/itaskid">
             <h:switchCheckbox checkedValue="Y" uncheckedValue="N"/>
           </l:empty>              
              
           </r:field>
                      
           <r:field fieldName="biscancelgres" label="修改说明" onRefreshFunc="getModifyDesc" width="200">
              
           </r:field>
                             
                                                          
         </r:datacell>
       </w:tabPage>
    
    </w:tabPanel>

  </w:layoutPanel>
</w:layout>
      <dataform>
      
<div style="display:none">
  <r:datacell pageSize="1000" id="grdSchedule" height="320"  width="100%" linkId="gress" linkField="schedules">
    <r:toolbar location="top" tools="edit:refresh"/>
    <r:field fieldName="dbusinessdate" label="入住日期">
      <h:text readonly="true"/>
    </r:field>
    <r:field fieldName="nroomrate" label="原房价/晚">
      <h:text readonly="true"/> 
    </r:field> 
    <r:field fieldName="nrate" label="确认价格/晚">
      <h:text/>
    </r:field>  
    <r:field fieldName="ncommissionprice" label="佣金">
      <h:text readonly="true"/>
    </r:field>    
    <r:field fieldName="total" label="小计">
      <h:text readonly="true"/>           
    </r:field>                                                  
  </r:datacell>
        
</div>
          <table align="center" border="0" width="100%" class="form_table">
            <tr>
              <td class="form_label">
                调整后价格合计
              </td>
              <td colspan="1">
                <h:text readonly="true" style="width:200px;" id="txtPriceAmt"/>
              </td>
              <td class="form_label">
                原房价
              </td>
              <td colspan="1">
                <h:text readonly="true"  style="width:200px;" id="txtOriginAmt"/>
              </td>
              <td class="form_label">
                折扣
              </td>
              <td colspan="1">
                <h:text readonly="true"  style="width:200px;" id="txtDiscount"/>
              </td>
            </tr>
            <tr>
              <td class="form_label">
                预付比例
              </td>
              <td colspan="1">
                 <h:text property="weordertasks/npaypercent" readonly="true" style="width:200px;" id="txtPrepayPercent"/>
              </td>
              <td class="form_label">
                预付金额
              </td>
              <td colspan="1">
                 <h:text  style="width:200px;" readonly="true" readonly="true"  id="txtPrepayAmt"/>
              </td>
              <td class="form_label">
                佣金
              </td>
              <td colspan="1">
                 <h:text readonly="true"  style="width:200px;" id="txtCommision"/>
              </td>
            </tr>
            <tr>
              <td class="form_label">
                付款方式
              </td>
              <td colspan="1">
                <d:select property="weordertasks/cpaymenttype" style="width:200px;" nullLabel="请选择" dictTypeId="HMS_PAYMENT_TYPE" disabled="<%=isReadonly %>"/>
              </td>
              <td class="form_label">
                 付款摘要
              </td>
              <td colspan="3">
                <h:text property="weordertasks/cpaymentdescription" style="width:100%;"/>
              </td>
            </tr>
            
            <%
               if (isTodo == true){
               
               
               if (isTodo == true){

             %>
            <tr>
              <td class="form_label">
                审批意见
              </td> 
              <td colspan="5" >
                 <h:textarea property="task/advise" style="width:100%"/>
              </td>
            </tr>  
            <tr class="form_bottom">
              <td colspan="6">          
                <input type="button" value="审批" class="button" onclick="auditOrder()">   
                <input type="button" value="驳回" class="button" onclick="rejectOrder()">                                  
              </td>
            </tr> 
            
            <%}} %>
          </table>
      </dataform>
      
      <input type="hidden" name="commitAction" value="">
      
    </h:form>
    <script>
    
      groomfield = "inewroomid";
      garrfield = "dnewarrdate"; 
      gdepfield = "dnewdepdate";
      groomno = "cnewroomno"    
      
      function submitDatacell(frm) {
        if (checkForm(frm)) {
          
          //设置数据修改标志
          var dcell = $id('gress'); 
          var eties = dcell.dataset.getAlltEntities();
          for(var i = 0; i < eties.length; i++){
             if (eties[i].getProperty("iapplyid")){
               eties[i].setProperty("changed", 'Y');
             }else if (gresChanged(eties[i]) == true){
               eties[i].setProperty("changed", 'Y');
             }
          }
          dcell.submitAllByHidden();
          return true;
        }
        $name("commitAction").value = "";
        return false;
      }
      
      function commitOrder(){
         //提交订单
         $name("commitAction").value = "S";
         $name("_eosFlowAction").value = "commit";
         if (submitDatacell($name("data_form"))){
           $name("data_form").submit();
         }
      }
      
      function auditOrder(){
        //审批订单
        $name("commitAction").value = '<b:write property="weordertasks/cstatus"/>';
        $name("task/aciton").value = "APPROVE";
         if (submitDatacell($name("data_form"))){
           $name("data_form").submit();
         }
      }
      
      $id("gress").beforeEdit = beforeModifyEdit;
      $id("gress").beforeDel = beforeModifyDel;
      $id("gress").afterAdd = function(e){
         var ety = $id("gress").getEntity(e);
         ety.setPropertyByFieldName("cstatus", "R");
      };
      
      
      function setRoomId(args){
         $id("gress").activeEntity.setPropertyByFieldName("inewroomid", args[0]);
         args[0] = args[1];
      }
      
      <l:equal property="_eosLastAccessAction" targetValue="insert">
        $id("txtPrepayPercent").value = gCfg.PREPAY_PERCENT + "";
      </l:equal>
      
      $id("gress").afterAdd = afterGressAdd;
      $id("gress").afterDel = afterGressDelete;
      $id("gress").afterEdit = afterGressEdit;
      
      //line grid event
      $id("grdSchedule").afterAdd = sumAmount;
      $id("grdSchedule").afterDel = sumAmount;
      $id("grdSchedule").afterEdit = sumAmount;
      
      $id("gress").loadData = function(){
        var xmlZone = document.getElementById(this.id + "_xml");
        this.dataXML = xmlZone ? xmlZone.innerHTML : null;
    var xmlDom;
    if (this.dataXML && this.dataXML !== "<json/>") {
        this.dataset = Dataset.create(this.dataXML, this.xpath);
        xmlDom = createXmlDom();
        xmlDom.loadXML(this.dataXML);
        var pagecond = xmlDom.selectSingleNode("/root/data/page");
        this.freshPagePilot(pagecond);
        initGress();    
        return
    }
    if (this.onLoadData() !== false) {
        if (!this.queryAction) return;
        var ajax = new HideSubmit(this.queryAction),
            param = this.getQueryForm();
        if (this.queryParam) param += this.queryParam;
        if (this.pageParam) param += this.pageParam;
        if (this.initParamFunc) {
            try {
                param += eval(this.initParamFunc + "()")
            } catch(e) {
                $handle(e)
            }
        }
        if (param == "") param = null;
        if (this.paramFormId) {
            var form = $id(this.paramFormId);
            if (form) for (var i = 0; i < form.elements.length; i++) {
                var elem = form.elements[i];
                if (elem.name) ajax.addParam(elem.name, getElementValue(elem))
            }
        }
        if (this.paramList) for (i = 0; i < this.paramList.length; i++) {
            elem = this.paramList[i];
            if (elem) ajax.addParam(elem.key, elem.value)
        }
        ajax.loadData(param);
        xmlDom = ajax.retDom;
        this.dataset = Dataset.create(xmlDom, this.xpath, this.getSubmitXpath());
        pagecond = xmlDom.selectSingleNode("/root/data/page");
        this.freshPagePilot(pagecond);
        this.afterLoadData(ajax)
    }
    
    

      }
           
      //开始刷新
      gressRefreshQueue();
                        
      CalendarEditor.refreshTime = function (A) {
        if (CalendarEditor.showTime) {
          A.setHours(CalendarEditor.timeSelect.getHours());
          A.setMinutes(CalendarEditor.timeSelect.getMinutes());
          A.setSeconds("00")
        }
        return A
      };
      
      CalendarEditor.showEditor = function () {
            if (CalendarEditor.showTime) {
                CalendarEditor.timeContainer.style.display = "";
                CalendarEditor.okBtn.style.display = "";
                if (isFF) {
                    CalendarEditor.container.style.height = "226px";
                    CalendarEditor.container.firstChild.style.height = "226px"
                }
            } else {
                CalendarEditor.timeContainer.style.display = "none";
                CalendarEditor.okBtn.style.display = "none";
                if (isFF) {
                    CalendarEditor.container.style.height = "200px";
                    CalendarEditor.container.firstChild.style.height = "200px"
                }
            }
            CalendarEditor.initCalendarEvent();
            
            if (!CalendarEditor.value){
               var field = $id("gress").activeField;
               if (field && field.fieldName == "dnewdepdate"){
                 CalendarEditor.value = dateToString(new Date(), 'yyyy-MM-dd') + " 12:00:00";
               }
            }
            CalendarEditor.freshDate(CalendarEditor.value);
            CalendarEditor.freshTimeComp();
            CalendarEditor.showStatus = true;
            CalendarEditor.container.style.display = "";
            var A = $id("_eos_calendar_editor_container", CalendarEditor.doc);
            initShadow(A, CalendarEditor.doc)
      };
                              
    </script>
  </body>
</html>
